package com.lebang.service;

import com.lebang.entity.task.TaskComments;
import com.lebang.entity.task.TaskScreenshot;
import com.lebang.example.TaskCommentsExample;
import com.lebang.mapper.TaskCommentsMapper;
import com.lebang.mapper.TaskScreenshotMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentsService {

    @Autowired
    private TaskCommentsMapper taskCommentsMapper;
    @Autowired
    private TaskScreenshotMapper taskScreenshotMapper;


    public Long count(TaskCommentsExample example) {

        return taskCommentsMapper.countByExample(example);
    }

    public List<TaskComments> selectAll(TaskCommentsExample example){
        return taskCommentsMapper.selectByExample(example);
    }

    public void commonSwitch(TaskComments po) {
        TaskComments taskComments = taskCommentsMapper.selectByPrimaryKey(po.getId());
        taskComments.setStatus(po.getStatus());
        taskCommentsMapper.updateByPrimaryKeySelective(taskComments);
        TaskScreenshot taskScreenshot = taskScreenshotMapper.selectByTaskId(taskComments.getTaskId());
        if(po.getStatus()==0){
            taskScreenshot.setStatus("Off");
        }
        if(po.getStatus()==1){
            taskScreenshot.setStatus("On");
        }
        if(po.getStatus()==2){
            taskScreenshot.setStatus("Wait");
        }
        taskScreenshotMapper.updateById(taskScreenshot);

    }
}